package com.ruoyi.project.system.startpage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.startpage.domain.StartPage;
import com.ruoyi.project.system.startpage.service.IStartPageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 首页Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@Controller
@RequestMapping("/system/startpage")
public class StartPageController extends BaseController
{
    private String prefix = "system/startpage";

    @Autowired
    private IStartPageService startPageService;

    @RequiresPermissions("system:startpage:view")
    @GetMapping()
    public String startpage()
    {
        return prefix + "/startpage";
    }

    /**
     * 查询首页列表
     */
    @RequiresPermissions("system:startpage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StartPage startPage)
    {
        startPage();
        List<StartPage> list = startPageService.selectStartPageList(startPage);
        return getDataTable(list);
    }

    /**
     * 导出首页列表
     */
    @RequiresPermissions("system:startpage:export")
    @Log(title = "首页", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StartPage startPage)
    {
        List<StartPage> list = startPageService.selectStartPageList(startPage);
        ExcelUtil<StartPage> util = new ExcelUtil<StartPage>(StartPage.class);
        return util.exportExcel(list, "首页数据");
    }

    /**
     * 新增首页
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页
     */
    @RequiresPermissions("system:startpage:add")
    @Log(title = "首页", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StartPage startPage)
    {
        return toAjax(startPageService.insertStartPage(startPage));
    }

    /**
     * 修改首页
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StartPage startPage = startPageService.selectStartPageById(id);
        mmap.put("startPage", startPage);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页
     */
    @RequiresPermissions("system:startpage:edit")
    @Log(title = "首页", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StartPage startPage)
    {
        return toAjax(startPageService.updateStartPage(startPage));
    }

    /**
     * 删除首页
     */
    @RequiresPermissions("system:startpage:remove")
    @Log(title = "首页", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(startPageService.deleteStartPageByIds(ids));
    }
}
